package cn.aitstone.system.controller;

import cn.aitstone.basic.annotation.PreAuthorize;
import cn.aitstone.basic.utils.AjaxResult;
import cn.aitstone.basic.utils.PageList;
import cn.aitstone.system.domain.DictionaryDetail;
import cn.aitstone.system.query.DictionaryDetailQuery;
import cn.aitstone.system.service.IDictionaryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @Description: 数据字典明细控制类
 * @Author: Sheldon
 * @Version: 1.0
 * @Date:  2022/6/30 23:45
 */
@RestController
@RequestMapping("/dictionarydetail")
@Api(value = "部门的API",description="部门的CRUD功能")
public class DictionaryDetailController {
    @Autowired
    private IDictionaryDetailService dictionaryDetailService;

    /**
     * @Title: loadById
     * @Description: 根据员工id查询
     * @Author: Sheldon
     * @Version: 1.0
     * @Date:  2022/6/24 11:08
     * @Parameters: [id]
     * @Return cn.aitstone.org.domain.Employee
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public DictionaryDetail loadById(@ApiParam(value="部门表的主键",required = true) @PathVariable("id") Long id){
        return dictionaryDetailService.loadById(id);

    }

    /**
     * @Title: loadAll
     * @Description: 查询所有
     * @Author: Sheldon
     * @Version: 1.0
     * @Date:  2022/6/24 11:08
     * @Parameters: []
     * @Return java.util.List<cn.aitstone.org.domain.Employee>
     */
    @GetMapping
    public List<DictionaryDetail> loadAll(){
        return dictionaryDetailService.loadAll();
    }

    /**
     * @Title: remove
     * @Description: 根据id删除
     * @Author: Sheldon
     * @Version: 1.0
     * @Date:  2022/6/24 11:47
     * @Parameters: [id]
     * @Return cn.aitstone.basic.utils.AjaxResult
     */
    @DeleteMapping("/{id}")
    @PreAuthorize(name = "删除数据字典明细", sn="dictionarydetail:delete")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            dictionaryDetailService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }

    }

    /**
     * @Title: addOrUpt
     * @Description: 新增和修改接口
     * @Author: Sheldon
     * @Version: 1.0
     * @Date:  2022/6/24 11:47
     * @Parameters: [employee]
     * @Return cn.aitstone.basic.utils.AjaxResult
     */
    @PutMapping
    @PreAuthorize(name = "保存修改数据字典明细", sn="dictionarydetail:addOrUpt")
    public AjaxResult addOrUpt(@RequestBody DictionaryDetail dictionaryDetail){
        try {
            if (dictionaryDetail.getId() == null){
                dictionaryDetailService.save(dictionaryDetail);
            } else{
                dictionaryDetailService.update(dictionaryDetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }

    }

    /**
     * @Title: queryData
     * @Description: 高级查询分页接口
     * @Author: Sheldon
     * @Version: 1.0
     * @Date:  2022/6/24 11:48
     * @Parameters: [employeeQuery]
     * @Return cn.aitstone.basic.utils.AjaxResult
     */
    @PostMapping
    @PreAuthorize(name = "获取数据字典明细列表", sn="dictionarydetail:list")
    public PageList<DictionaryDetail> queryData(@RequestBody DictionaryDetailQuery dictionaryDetailQuery){
        PageList<DictionaryDetail> data = dictionaryDetailService.queryData(dictionaryDetailQuery);
        return data;

    }

    /**
     * @Title: batch
     * @Description: 批量删除
     * @Author: Sheldon
     * @Version: 1.0
     * @Date:  2022/6/25 11:18
     * @Parameters:
     * @Return
     */
    @PatchMapping
    @PreAuthorize(name = "批量删除数据字典明细", sn="dictionarydetail:batch")
    public AjaxResult batch(@RequestBody Long[] ids){
        try {
            dictionaryDetailService.batchdel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }

    }

}
